package web;

import java.util.Date;
import java.util.List;

import tool.DateUtils;
import vo.SentenceType;
import business.SentenceTypeService;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.Preparable;

@SuppressWarnings("unchecked")
public class SentenceTypeAction implements Preparable {
	private SentenceTypeService service;
	private List<SentenceType> sentenceTypes;
	private String name;

	public String listSentenceType() {
		this.sentenceTypes = service.getAll();
		return Action.SUCCESS;
	}

	public String add() {

		return listSentenceType();
	}

	// 添加paper
	public String insertSentenceType() {
		System.out.println("insert Sentence type:" + name);
		SentenceType sentenceType = new SentenceType();
		sentenceType.setName(name);
		Date today = new Date();
		String createdAt = DateUtils.date2Str(today, "-");
		sentenceType.setCreatedAt(createdAt);
		service.insert(sentenceType);

		return "insertSentenceType";
	}

	public List<SentenceType> getSentenceTypes() {
		return this.sentenceTypes;
	}

	public void prepare() throws Exception {
		// if (id != null)
		// employee = service.find(id);
	}

	public void setSentenceTypeService(SentenceTypeService service) {
		this.service = service;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}